package com.example.demo.controller;

import com.example.demo.entity.Stu;
import com.example.demo.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/user")
public class Controller {

    @Autowired

    private StuService stuService;

    @RequestMapping("/id")
    public Stu getUserById(Integer id) {
        if (id == null) return null;
        return stuService.getUserById(id);
    }
//    @RequestMapping("/all")
//    public List<Stu> getStu(Stu stu){
//        return stuService.getStu();
//    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Integer add(@RequestBody Stu stu){
        return stuService.add(stu);
    }

    @RequestMapping("/update")
    public Integer updateName(Stu stu){
        return stuService.updateName(stu);
    }

    //@RequestMapping(value = "/del",method = RequestMethod.POST)


    @RequestMapping("/del")
    public Integer delById(Integer id){
        return stuService.delById(id);
    }
}
